# CMake 最低版本号要求
cmake_minimum_required(VERSION 3.20)

# 定义变量
option(Build_DEBUG "debug or release?" OFF)
option(Build_TEST "debug or release?" 1)
if (Build_DEBUG)
    message(STATUS "VAR2 IS tru 1 " ${Build_DEBUG})
endif()
message(STATUS "VAR2 IS tru 2 " ${Build_TEST})

# 定义变量
set(VAR1 ON)
set(VAR2 OFF)
set(VAR3 1 2 4)

# IF引用变量，直接使用变量名代表对变量的引用。如果换成${变量名},则会先
# 将${变量名}替换成它的值，然后取它的值所对应的的变量的值
IF(VAR1)    #直接引用
    message(STATUS "VAR IS tru  1 " ${VAR1})
ELSEIF(${VAR2}) #  ${VAR2}的值为OFF，而变量OFF未定义，所以为FALSE
    message(STATUS "VAR2 IS tru 2" ${VAR2})
ELSE()
    message(STATUS "VAR3 IS tru 3 " ${VAR3})
ENDIF()

if(DEFINED VAR1) #变量是否定义过了
    message(STATUS "DEFINED 4 ")
endif()
if(NOT VAR2) #取变量的相反值
    message(STATUS "NOT 5 ")
endif()
if(VAR3 MATCHES ";") #变量是否含有";"，一般在用set()设置变量传递多个参数时，该变量都含有";"
    message(STATUS "MATCHES ;")
endif()

#执行如下
# cmake -DBuild_DEBUG=OFF -P if_option.cmake